module Main where

import Control.Monad
import System.Environment (getArgs)
import Control.Concurrent
import Control.Concurrent.Async

import Network
import qualified Network.Socket as NetS
import Text.Printf
import System.IO

import qualified Data.ByteString.Lazy.Char8 as BL

import Net

msg_a :: BL.ByteString
msg_a = BL.take 10240 $ BL.repeat 'a'

msg_b :: BL.ByteString
msg_b = BL.take 10240 $ BL.repeat 'b'


msg :: Char -> BL.ByteString
msg c = BL.take 10240 $ BL.repeat c


main = withSocketsDo $ do
  sock <- tcpSocket
  addr <- getAddr
  --NetS.connect sock ( NetS.SockAddrInet (fromIntegral port) localhost )
  NetS.connect sock addr
  a1 <- async (sendData sock msg_a)
  a2 <- async (sendData sock msg_b)
  a3 <- async (sendData sock $ msg 'c')  
  a4 <- async (sendData sock $ msg 'd')  

  wait a1
  wait a2
  wait a3
  wait a4
  NetS.close sock
  NetS.close sock


